package main

func canThreePartsEqualSum(A []int) bool {
	if len(A) < 3 {
		return false
	}
	sum := 0
	for _, v := range A {
		sum += v
	}
	if sum%3 != 0 {
		return false
	}
	target := sum / 3
	s0 := 0
	i := 0
	for ; i < len(A); i++ {
		s0 += A[i]
		if s0 == target {
			break
		}
	}
	if s0 != target {
		return false
	}
	s1 := 0
	j := len(A) - 1
	for ; j > i+1; j-- {
		s1 += A[j]
		if s1 == target {
			break
		}
	}
	if s1 != target {
		return false
	}
	return true
}

func main() {
	println(canThreePartsEqualSum([]int{3, 3, 6, 5, -2, 2, 5, 1, -9, 4}))
}
